package com.competitions.easydubbing.controller;

import com.alibaba.fastjson.JSONObject;
import com.competitions.easydubbing.entity.Result;
import com.competitions.easydubbing.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Mapler
 * @since 2021-5-20
 */
@RestController
@RequestMapping(value = "/auth")
public class UserController {
    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public ResponseEntity<Result> register(@RequestBody JSONObject data){
        return userService.register(data);
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResponseEntity<Result> login(@RequestBody JSONObject data){
        return userService.login(data);
    }

    @RequestMapping(value = "/findUserInfo",method = RequestMethod.POST)
    public ResponseEntity<Result> findUserInfo(@RequestBody JSONObject data){
        return userService.findUserInfo(data);
    }

    @RequestMapping(value = "/userInfo",method = RequestMethod.POST)
    public ResponseEntity<Result> userInfo(@RequestBody JSONObject data){
        return userService.updateUserData(data);
    }

    @RequestMapping(value = "/userAvatar",method = RequestMethod.POST)
    public ResponseEntity<Result> userAvatar(@RequestParam int uid, @RequestBody MultipartFile avatar){
        return userService.updateAvatar(uid,avatar);
    }
}
